home *** CD-ROM | disk | FTP | other *** search
- /* free.c --- p. 136 */
- # include <stdio.h>
- # include <stdlib.h>
- # include <alloc.h>
- # define MAX_CHR 80
- main()
- {
- char *buffer;
- /* Allocate room for string and check for NULL */
- if( (buffer = (char *)malloc(MAX_CHR)) == NULL)
- {
- printf("Allocation Failed.\n");
- exit(0);
- }
- printf("Buffer allocated. Enter string to store: ");
- gets(buffer);
- printf("\nYou entered: %s\n", buffer);
- free((void *)buffer); /* Deallocate the memory */
- printf("Buffer deallocated.\n");
- }